package cc.eddic.pratice.programmingparadigms.emp02list;

import cc.eddic.pratice.programmingparadigms.Result;
import cc.eddic.pratice.programmingparadigms.ResultComparator;
import cc.eddic.pratice.programmingparadigms.ResultPredicate;

import java.util.Objects;

public interface ResultList {
    void add(Result result);

    Result get(int index);

    int size();

    default int capacity() {
        return 0;
    }


    @Deprecated

    Result findByGender(String gender);

    @Deprecated
    Result findByDepartment(String department);

    @Deprecated
    Result findByJobTitle(String jobTitle);

    default Result findByKey(String Key) {
        for (int i = 0; i < this.size(); i++) {
            if (Objects.equals(this.get(i).getKey(), Key))
                return this.get(i);
        }
        return null;

    }

    default Result find(ResultPredicate predicate) {
        for (int i = 0; i < size(); ++i) {
            Result r = get(i);
            if (predicate.test(r)) {
                return r;
            }
        }
        return null;
    }

    default void sort(ResultComparator comparator) {

    }

    default Result[] toArray() {
        return new Result[0];
    }

}
